<html>
<head>
	<script src="settings.js"></script>
	
<script type="text/javascript">
function setUp() {
	$('form').reset();
}

function testIntegerFormat() {
	assertTrue("basic int", Validation.isInteger("12345"));
	assertTrue("signed int", Validation.isInteger("-12345", true));
	assertFalse("int front", Validation.isInteger("a12345"));
	assertFalse("int end", Validation.isInteger("12345a"));
	assertFalse("int mid", Validation.isInteger("12a345"));
	assertFalse("int as float", Validation.isInteger("123.45"));
}

function testValidationInstance() {
	assertNotUndefined(Validation);
}

function testIsFloat() {
	assertTrue("plain", Validation.isFloat("1,123.45"));
	assertTrue("dot at end", Validation.isFloat("123."));
	assertTrue("dot at begin", Validation.isFloat(".45"));
	assertTrue("no dot", Validation.isFloat("12345"));
	assertFalse("unsigned", Validation.isFloat("-12345"));
	assertTrue("signed", Validation.isFloat("-12345", true));
	assertFalse("leading char", Validation.isFloat("a123.45"));
	assertFalse("double dot", Validation.isFloat("123.4.5"));
}

function testIsCurrency() {
	assertTrue("plain curr", Validation.isCurrency("$1,123.45"));
	assertTrue("plain curr 2", Validation.isCurrency("1123.45"));
	assertFalse("dot at end curr", Validation.isCurrency("123."));
	assertTrue("dot at begin curr", Validation.isCurrency(".45"));
	assertTrue("no dot curr", Validation.isCurrency("12345"));
	assertTrue("signed curr", Validation.isCurrency("($12345)", true));
	assertTrue("signed curr 2", Validation.isCurrency("-12345", true));
	assertFalse("leading char float", Validation.isCurrency("a123.45"));
}

function testConversion() {
	assertEquals("mm/dd/yyyy failed", "20040113000000", Validation.toDateString("1/13/2004", "M/DD/YYYY")); 
	assertEquals("feb 29, 2004 failed", "20040229000000", Validation.toDateString("2/29/2004", "M/DD/YYYY"));
	assertEquals("1 PM time", "00010101130000", Validation.toDateString("01:00pm", "HH:NN AP"));
	assertEquals("12 PM time", "00010101120000", Validation.toDateString("12:00pm", "HH:NN AP"));
	assertEquals("11 PM time", "00010101230000", Validation.toDateString("11:00pm", "HH:NN AP"));
	assertEquals("23:00 time", "00010101230000", Validation.toDateString("23:00", "HH24:NN"));
	assertEquals("full conversion", "20030112235959", Validation.toDateString("20030112235959", "yyyymmddhh24nnss"));
	assertEquals("1 PM time in short hour form", "00010101130000", Validation.toDateString("1:00pm", "H:NN AP"));
	assertEquals("9 AM military time in short hour form", "00010101090000", Validation.toDateString("9:00", "H24:NN"));
}
function testComparison() {
	assertEquals("dates equal",  Validation.toDateString("01/01/2003","MM/DD/YYYY"), Validation.toDateString("01/01/2003","MM/DD/YYYY"));
	assertTrue("date lt", Validation.toDateString("01/01/2003","MM/DD/YYYY")<Validation.toDateString("01/02/2003","MM/DD/YYYY"));
	assertTrue("date gt", Validation.toDateString("01/01/2003","MM/DD/YYYY")>Validation.toDateString("01/01/2002","MM/DD/YYYY"));
	assertTrue("time compare", Validation.toDateString("01:00pm","HH:NN AP")>Validation.toDateString("12:00pm","HH:NN AP"));
	assertTrue("time compare 2", Validation.toDateString("01:00pm","HH:NN AP")>Validation.toDateString("12:00","HH24:NN"));
}

function testInvalidFormat() {
	assertUndefined("13th month failed", Validation.toDateString("13/13/2004", "MM/DD/YYYY"));
	assertUndefined("32nd day failed", Validation.toDateString("1/32/2004", "M/D/YYYY"));
	assertUndefined("feb 29, 2003 failed", Validation.toDateString("02/29/2003", "MM/DD/YYYY"));
	assertUndefined("year format:5", Validation.toDateString("11/13/20045", "MM/DD/YYYY"));
	assertUndefined("year format:3", Validation.toDateString("11/13/200", "MM/DD/YYYY"));
	assertUndefined("60th minute", Validation.toDateString("00:60", "HH24:NN"));
	assertUndefined("24th hour", Validation.toDateString("24:00", "HH24:NN"));
}


</script>
</head>
<body>
	<form id="form">
		<input required="required" id="r" />
		<input id="a" />
	</form>
</body>
</html>